package com.heima.wemedia.v1.controller;

import com.heima.common.dtos.PageResult;
import com.heima.common.dtos.ResponseResult;
import com.heima.model.media.dtos.WmMaterialDto;
import com.heima.wemedia.entity.WmMaterial;
import com.heima.wemedia.service.WmMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

@RestController
public class MaterialController {

    @Autowired
    private WmMaterialService materialService;

    /**
     * 素材的分页查询
     * */
    @PostMapping("/api/v1/material/list")
    public PageResult<WmMaterial> pageQuery(@RequestBody WmMaterialDto dto){
        return materialService.pageQuery(dto);
    }

    /**
     * 图片上传
     * */
    @PostMapping("/api/v1/material/upload_picture")
    public ResponseResult<String> uploadPicture(@RequestParam("multipartFile") MultipartFile file){
        String url = materialService.uploadPicture(file);
        return ResponseResult.ok(url);
    }
}
